<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>万息金融-后台管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8"/>
    <link rel="stylesheet" href="/admin/css/font.css">
    <link rel="stylesheet" href="/admin/css/xadmin.css">
    <script src="/admin/js/myAjax.js"></script>
    <script src="/admin/js/common.js"></script>
    <script src="/admin/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/admin/js/xadmin.js"></script>
    <script src="/admin/js/intercept.js"></script>


</head>

<body>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">

        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5">
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="修改时间起点" name="startTime" id="start">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input class="layui-input" autocomplete="off" placeholder="修改时间截止" name="endTime" id="end">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="name" placeholder="请输入业务分类名" autocomplete="off"
                                   class="layui-input"></div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-submit="" lay-filter="search">
                                <i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-body ">
                    <!--    <table class="layui-table"
                               lay-data="{toolbar: '#toolbarDemo',id:'test'}"
                               lay-filter="test">-->
                    <table id="test" lay-data="{toolbar: '#toolbarDemo',id:'test'}" lay-filter="bcfilt"></table>
                        <!-- <thead>
                         <tr>
                             <th lay-data="{field:'name', width:120, sort: true}">分类名</th>
                             <th lay-data="{field:'cateLogo', minWidth: 150,templet: '#businessLogo'}">业务LOGO</th>
                             <th lay-data="{field:'cateSynopsis', minWidth:80}">业务简介</th>
                             <th lay-data="{field:'createTime',  minWidth: 100}">创建时间</th>
                             <th lay-data="{field:'updateTime', sort: true}">修改时间</th>
                             <th lay-data="{field:'remark'}">批注</th>
                             <th lay-data="{fixed: 'right', width: 160, align: 'center', toolbar: '#barDemo'}"
                                 rowspan="2">操作
                             </th>
                         </tr>
                         </thead>-->

                </div>
            </div>
        </div>
    </div>

</div>
</div>
</body>
<script type="text/html" id="businessLogo">
    <img style="max-width: 50px" src="{{d.cateLogo}}">
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="update">编辑</a>
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="delete">删除</a>
</script>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-sm" lay-event="add"> 新增</button>
    </div>
</script>
<script>
    layui.use(['laydate', 'form', 'jquery', 'table'],

        function () {
            var laydate = layui.laydate
                , $ = layui.jquery
                , form = layui.form
                , table = layui.table;


            table.render({
                elem: '#test'
                , page: true
                , url: ipAddress()+"/business/category/g"
                , method: 'get'
                , text: '没有数据'
                , toolbar: '#toolbarDemo'
                , cols: [[
                    {field: 'name', width: 120, sort: true, title: '分类名'}
                    , {field: 'cateLogo', minWidth: 150, templet: '#businessLogo', title: '业务LOGO'}
                    , {field: 'cateSynopsis',event:'show', minWidth: 80, title: '业务简介'}
                    , {field: 'createTime', minWidth: 100, title: '创建时间'}
                    , {field: 'updateTime', sort: true, title: '修改时间'}
                    , {field: 'remark', title: '批注'}
                    , {fixed: 'right', width: 160, align: 'center', toolbar: '#barDemo', title: '操作'}
                ]]
            });


            table.on('toolbar(bcfilt)', function (obj) {

                switch (obj.event) {
                    case 'add':
                        layer.open({
                            title: '信息修改',
                            shade: 0.1,
                            area: ['1000px', '500px'],
                            type: 2,
                            content: './bCAdd.html',
                        })
                        break;
                }
                ;
            });

            form.on('submit(search)',
                function (data) {
                    table.render({
                        elem: '#test'
                        , page: true
                        ,url:ipAddress()+"/business/category/g"
                        , text: '没有数据'
                        , toolbar: '#toolbarDemo'
                        , where: data.field
                        , cols: [[
                            {field: 'name', width: 120, sort: true, title: '分类名'}
                            , {field: 'cateLogo', minWidth: 150, templet: '#businessLogo', title: '业务LOGO'}
                            , {field: 'cateSynopsis', minWidth: 80, title: '业务简介'}
                            , {field: 'createTime', minWidth: 100, title: '创建时间'}
                            , {field: 'updateTime', sort: true, title: '修改时间'}
                            , {field: 'remark', title: '批注'}
                            , {fixed: 'right', width: 160, align: 'center', toolbar: '#barDemo', title: '操作'}
                        ]]
                    });
                    return false;
                })
            //执行一个laydate实例
            laydate.render({
                elem: '#start' //指定元素

            });

            //执行一个laydate实例
            laydate.render({
                elem: '#end' //指定元素
            });


            table.on('tool(bcfilt)',
                function (obj) {

                    var data = obj.data; //获得当前行数据
                    switch (obj.event) {
                        case 'show':
                            layer.open({
                                type: 1,
                                title: false,
                                closeBtn: 0,
                                area: ['516px','400px'],
                                // skin: 'layui-layer-nobg', //没有背景色
                                shadeClose: true,
                                content: '<div>'+data.cateSynopsis+' </div>'
                            });
                            break;
                        case 'delete':
                            layer.confirm('确认要删除吗？', function (index) {
                                let indx = table.cache.test.length;
                                //发异步删除数据
                                let res = myAjax(ipAddress()+'/business/category/d/'+data.id, {}, "delete");
                                let pg=$(".layui-laypage-curr").children().eq(1).text();
                                if (res.count == 1) {
                                    if (indx == 1) {
                                        table.reload('test', {page: {curr: pg-1}})
                                    } else {
                                        table.reload('test', {})
                                    }
                                    layer.msg('已删除!', {icon: 1, time: 1000});
                                } else {
                                    layer.msg('删除失败!', {icon: 1, time: 1000});
                                }
                            });


                            break;
                         case 'update':
                            let res = myAjax(ipAddress()+'/business/category/g/'+data.id, {}, "get");
                            sessionStorage.setItem("businessCateId",data.id);
                            console.log(res);
                            layer.open({
                                title: '信息修改',
                                shade: 0.1,
                                area: ['1000px', '500px'],
                                type: 2,
                                content: './bCUpdate.html',
                                success: function (layero, index) {
                                    var body = layer.getChildFrame('body', index);
                                    body.find('form').find('#name').val(res.data.name);
                                    body.find('form').find('#id').val(data.id);
                                    body.find('form').find('#Logo').attr("src", res.data.cateLogo);
                                    // body.find('form').find('#layeditDemo').text(res.data.cateSynopsis);
                                    body.find('form').find('#remark').val(res.data.remark);
                                }
                            })
                            break;
                    };
                });
        });

</script>
</html>